package GUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CunPanel extends JPanel implements ActionListener {
    private ImageIcon imageIcon = Utilimg.getIcon("/img/buttonOff.jpg");
    private ImageIcon imageIcon1 = Utilimg.getIcon("/img/buttonSure.jpg");
    private JButton cunjButton;
    private JButton cunjButton1;
    private Text2 frame;
    private JTextField jTextField;
    public CunPanel(Text2 frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        JLabel jLabel = new JLabel("存款:");
        jLabel.setBounds(200, 150, 100, 50);
        jLabel.setFont(new Font("宋体", Font.BOLD, 30));
        this.add(jLabel);

        jTextField=new JTextField();
        jTextField.setBounds(300, 160, 200, 30);
        this.add(jTextField);



        cunjButton = new JButton(imageIcon);
        cunjButton.setBounds(690, 250, 100, 50);
        this.add(cunjButton);
        cunjButton.addActionListener(this);

        cunjButton1 = new JButton(imageIcon1);
        cunjButton1.setBounds(0, 250, 100, 50);
        this.add(cunjButton1);
        cunjButton1.addActionListener(this);
    }
   public User cun(){
       double a= Double.valueOf(jTextField.getText());
       double b=frame.getLoginUser().getBalance();
       frame.getLoginUser().setBalance(a+b);
       return frame.getLoginUser();
   }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == cunjButton) {
            frame.switchPanel("menu");
        }else if(e.getSource()==cunjButton1){
            User loginuser=cun();
            JOptionPane.showMessageDialog(this,"存款成功");
            DBUtil dbUtil = new DBUtil();
            dbUtil.update(loginuser);
        }
    }

}
